package com.modules.listview;

import android.databinding.DataBindingUtil;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.base.recycleView.activity.BaseRecyclViewActivity;
import com.gml.gao.R;
import com.gml.gao.databinding.CommonRecyclview3Binding;
import com.modules.bean.User;
import com.view.inject.DaggerRecyclViewComponet;

import recyclerview.MultTemplateAdapter;
import recyclerview.nodata.LayoutController;
import recyclerview.swipetoloadlayout.OnLoadMoreListener;
import recyclerview.swipetoloadlayout.OnRefreshListener;
import recyclerview.swipetoloadlayout.SwipeToLoadLayout;


/**
 * Created by gml on 17/2/21.
 */

public class ListViewActivity extends BaseRecyclViewActivity<
        User,SimpleAdapter3,MainViewModel3> implements OnRefreshListener,
        OnLoadMoreListener, MultTemplateAdapter.OnItemCLickListener{



//    protected RecyclerView recyclerView;
//    protected SwipeToLoadLayout swipeToLoadLayout;
//    protected FrameLayout viewgroupFrame;
//    protected RelativeLayout rl_contnet_layout;
//    protected ImageView recyclerfm_title_line;
//
//
//    //网络出错  和数据为零 的时候 页面的处理类
//    protected LayoutController layoutController;
    protected boolean isLoading = false;
    protected int curPage = 1;
    protected boolean hasMorePage = false;
//    protected HeadFootAdapter adapter;
//    protected View end;

    CommonRecyclview3Binding binding;
    @Override
    protected void initInjector() {
        DaggerRecyclViewComponet.builder()
                .appComponent(getAppComponent())
                .activityModule(getActivityModule())
                .build()
                .inject(this);
    }
    @Override
    public void initView() {
        CommonRecyclview3Binding binding = DataBindingUtil.setContentView(this,
                R.layout.common_recyclview3);

        binding.setLvAdapter(mPresenter.gettSimpleAdapter());
        binding.swipeTarget.setLayoutManager(new LinearLayoutManager(this));//这里用线性显示 类似于listview

        binding.swipeToLoadLayout.setOnRefreshListener(this);
        binding.swipeToLoadLayout.setOnLoadMoreListener(this);

//        binding.layoutController = new LayoutController();
//        binding.layoutController.setContainerData(this,  "", new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                layoutController.showNormalView(viewgroupFrame);
//                mPresenter.findall();
//            }
//        });


//        binding.add.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mPresenter.findall();
//            }
//        });
    }

    @Override
    public void onLoadMore() {
        if (!isLoading && hasMorePage) {
            mPresenter.findall();
            isLoading = true;
        }
    }

    @Override
    public void onRefresh() {
//        binding.layoutController.showNormalView(viewgroupFrame);
        curPage = 1;
        if (!isLoading) {
            mPresenter.findall();
            isLoading = true;
        }
    }


    @Override
    public void onItemClick(View view) {

    }


}
